<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>水平垂直居中的实现</title>
  </head>
  <style>
    .container {
      position: relative;
      background: #0f0;
      width: 300px;
      height: 300px;
    }

    .box {
      position: absolute;
      width: 100px;
      height: 100px;
      background: red;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      margin: auto;
    }
  </style>
  <body>
    <header>头部</header>
    <nav>导航栏</nav>
    <section>区块（有语义化的div）</section>
    <main>主要区域</main>
    <article>主要内容</article>
    <aside>侧边栏</aside>
    <footer>底部</footer>
    <div class="container">
      <div class="box"></div>
    </div>
  </body>
</html>
<script></script>
